import React, { Component } from 'react';
import PropTypes from "prop-types"
import {Form,Select,Input} from "antd"
const { Option } = Select;
const Item =Form.Item
class Addfrom extends Component {
    static propTypes={
        setForm:PropTypes.func.isRequired,
        categorys:PropTypes.array.isRequired,
        parentId:PropTypes.string.isRequired,
    }
    componentWillMount(){
        this.props.setForm(this.props.form)
    }
    constructor(props) {
        super(props);
        console.log(props);
        this.state = {  }
    }
    render() { 
        const { getFieldDecorator } = this.props.form;
        const {categorys,parentId} =this.props
        return ( <Form>
            <Item>
                {
                    getFieldDecorator("parentId",{
                        initialValue:parentId
                    })(
                        <Select>
                            <Option value="0">一级分类</Option>
                            {
                                categorys.map((item)=>{
                                    return  <Option value={item._id} key={item._id}>{item.name}</Option>
                                })
                            }
                           
                        </Select>
                    )
                }
            </Item>
            <Item>
                {
                    getFieldDecorator("categoryName",{
                        initialValue:"",
                        rules:[
                            {
                                require:true,
                                message:"名称必须"
                            }
                        ]
                    })(
                        <Input placeholder="请输入分类名称"  />
                    )
                }
            </Item>
             </Form>);
    }
}
 
export default Form.create()(Addfrom);